1.16 Wildcards
Wildcards are utilized within the shell environment to match specified character ranges. The most frequently encountered wildcards are defined below:
| Symbol | Architectural Meaning / Matching Pattern |
|---|---|
| * | Matches zero or more arbitrary characters. |
| ? | Matches exactly one single arbitrary character. |
| [] | Matches any one single character enclosed within the brackets (defines a range or set). |
Examples:
$ ls *.c
$ ls file?.txt
Bracket Range Matching
| Pattern | Matching Envelope Rules |
|---|---|
| [character_set] | Matches any single character present within the specified set. |
| [character-character] | Matches any single character falling within the sequential range defined by the hyphen boundaries. |
| [!character_set] | Matches any single character not included within the specified set. |
| [^character_set] | Anchors the pattern to match strings that begin with the character configurations specified. |
Examples:
$ ls file[123].txt
Valid matches:
-
file1.txt
-
file2.txt
-
file3.txt
Invalid matches (will not match):
- file12.txt
$ ls file[a-z].txt
Valid matches:
-
filea.txt
-
fileb.txt
-
...
-
filez.txt
Standard Character Range Configurations
| Configuration | Explicit Matching Context Syntax |
|---|---|
| [a-z] | All lowercase alphabetic characters. |
| [A-Z] | All uppercase alphabetic characters. |
| [0-9] | All single-digit numeric characters. |
| [a-zA-Z] | All alphabetic characters regardless of case. |
| [a-z0-9] | All lowercase alphanumeric characters. |